import { createContext } from 'react';

import type { RbUploadProps, RbUploadStoreProps } from '../RbUploadProps';

const RbUploadStore = createContext<RbUploadStoreProps>({
  action: '',
  accept: '',
  multiple: false,
  disabled: false,
  beforeUploadEditEnabled: false,
  editModalTitle: '',
  singleFileMaxSize: 10,
  beforeUpload: () => {}
});
export default RbUploadStore;

export const RbUploadStoreProvider = (props: RbUploadProps) => {
  const {
    children,
    action,
    accept,
    multiple = true,
    disabled = false,
    beforeUploadEditEnabled = true,
    editModalTitle = '附件编辑',
    singleFileMaxSize = 10,
    beforeUpload = () => {}
  } = props;

  const value = {
    action,
    accept,
    multiple,
    disabled,
    beforeUploadEditEnabled,
    editModalTitle,
    singleFileMaxSize,
    beforeUpload
  };
  return <RbUploadStore.Provider value={value}>{children}</RbUploadStore.Provider>;
};
